package cc.risingsun.wing.dai;

import java.io.InputStream;

import javax.sql.DataSource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jolbox.bonecp.BoneCPConfig;
import com.jolbox.bonecp.BoneCPDataSource;

/**
 * 
 * @author iron.yin@gmail.com
 * @since 2012-8-14
 */
public class BoneCPDataSourceFactory implements IDataSourceFactory {

	private static final Logger logger = LoggerFactory
			.getLogger(BoneCPDataSourceFactory.class);

	private BoneCPDataSource datasource;

	public BoneCPDataSourceFactory() {
		InputStream in = ClassLoader.getSystemResourceAsStream("bonecp-config.xml");
		try {
			BoneCPConfig config = new BoneCPConfig(in, null);
			datasource = new BoneCPDataSource(config);
		} catch (Exception e) {
			logger.error(e.getMessage() + " system exit!", e);
		}
	}

	public DataSource getDataSource() {
		return this.datasource;
	}

}
